
package com.insigma.business.qrcode.soldier.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.soldier.dao.PlacementUnitInfoDao;
import com.insigma.business.qrcode.soldier.dto.PlacementUnitInfoBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.PlacementUnitInfoDO;
import com.insigma.business.qrcode.soldier.service.PlacementUnitInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("placementUnitInfoService")
public class PlacementUnitInfoServiceImpl implements PlacementUnitInfoService {

    @Autowired(required = false)
    private PlacementUnitInfoDao placementUnitInfoDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<PlacementUnitInfoDO> search(final PlacementUnitInfoBSearcher placementUnitInfoBSearcher) {
        return placementUnitInfoDao.search(placementUnitInfoBSearcher);
    }
   
    @Override
    public PlacementUnitInfoDO get(final String id){
        return placementUnitInfoDao.get(id);
    }

    
    @Override
    public Integer insert(final PlacementUnitInfoDO placementUnitInfoDO){
        placementUnitInfoDO.setId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_UNIT_INFO_ID));
        return placementUnitInfoDao.insert(placementUnitInfoDO);
    }

    
    @Override
    public Integer update(final PlacementUnitInfoDO placementUnitInfoDO){
        return placementUnitInfoDao.update(placementUnitInfoDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return placementUnitInfoDao.delete(id,modifierType,modifierId);
    }

    @Override
    public PlacementUnitInfoDO getOrInsertUnit(String unitName) {
        PlacementUnitInfoDO byName = placementUnitInfoDao.getByName(unitName);
        if (byName != null) {
            return byName;
        }
        byName = new PlacementUnitInfoDO();
        byName.setName(unitName);
        insert(byName);
        return byName;
    }

}
